<template>
  <div>
    <!-- 头部 -->
    <p-head @addnum="getnewsNav"></p-head>

    <!-- 横通 -->
    <div class="tips">
      <img src="../../img/news.jpg" alt="" />
      <div class="tips_title">
        <h1>新闻</h1>
        <h2>NEWS</h2>
      </div>
    </div>

    <div class="layout case_content">
      <template>
        <el-tabs
          v-model="newactiveName"
          type="card"
          @tab-click="handleclikNews"
        >
          <el-tab-pane label="全部" name="newall" :newsid="0">
            <div class="new_content1">
              <div class="big_new1">
                <div class="big_newpic1" @click="toNewdetail(new_one.id)">
                  
                    <img :src="new_one.thumb" alt="" />
               
                </div>
               
                <div class="big_newcontent1">
                  <p class="new_time1">{{ new_one.create_time }}</p>
                  
                  <h3 @click="toNewdetail(new_one.id)">
                    {{ new_one.title }}
                  </h3>
                  <p class="new_detail1">
                    {{ new_one.introduction }}
                  </p>
                  <div class="toNews1" @click="toNewdetail(new_one.id)">
                    了解详情
                  </div>
                </div>
                </router-link>
              </div>
              <div class="small_new1">
                <ul>
                  <template v-for="(item, key) in newlist" ：key="item.id">
                    <template v-if="key == 0"> </template>
                    <template v-else>
                      <li>
                        <div class="snew_content1">
                          <div class="snew_right1" @click="toNewdetail(item.id)">
                            <img :src="item.thumb" alt="" />
                          </div>
                          <div class="snew_left1">
                            <p>{{ item.create_time }}</p>
                            <h3 @click="toNewdetail(item.id)">
                              {{ item.title }}
                            </h3>

                            <div class="know1" @click="toNewdetail(item.id)">
                              了解详情
                            </div>
                          </div>
                        </div>
                      </li>
                    </template>
                  </template>
                  <!--                  <li>-->
                  <!--                    <div class="snew_content1">-->
                  <!--                      <div class="snew_right1">-->
                  <!--                        <img src="../../img/sc_pic.jpg" alt=""/>-->
                  <!--                      </div>-->
                  <!--                      <div class="snew_left1">-->
                  <!--                        <p>2021/11/06</p>-->
                  <!--                        <h3>-->
                  <!--                          北京企业网站设计之如何从哪些方面着手设计网站框架策划便于网站-->
                  <!--                        </h3>-->

                  <!--                        <div class="know1" @click="toNewdetail">了解详情</div>-->
                  <!--                      </div>-->
                  <!--                    </div>-->
                  <!--                  </li>-->
                </ul>
              </div>
              <template v-if="page < allpage">
                <div class="lod1" @click="domore(0)">加载更多</div>
              </template>
            </div>
          </el-tab-pane>
          <template v-for="em in new_nav" ：key="em.id">
            <el-tab-pane :label="em.name" :name="em.name" :newsid="em.id">
              <div class="new_content1">
                <div class="big_new1">
                  <div class="big_newpic1">
                    <router-link
                      :to="{ path: '/news', query: { new_id: new_one['id'] } }"
                    >
                      <img :src="new_one.thumb" alt="" />
                    </router-link>
                  </div>
                  <div class="big_newcontent1">
                    <p class="new_time1">{{ new_one.create_time }}</p>
                    <h3>
                      {{ new_one.title }}
                    </h3>
                    <p class="new_detail1">
                      {{ new_one.introduction }}
                    </p>
                    <div class="toNews1" @click="toNewdetail(new_one.id)">
                      了解详情
                    </div>
                  </div>
                </div>
                <div class="small_new1">
                  <ul>
                    <template v-for="(item, key) in newlist" ：key="item.id">
                      <template v-if="key == 0"> </template>
                      <template v-else>
                        <li>
                          <div class="snew_content1">
                            <div class="snew_right1">
                              <img :src="item.thumb" alt="" />
                            </div>
                            <div class="snew_left1">
                              <p>{{ item.create_time }}</p>
                              <h3>
                                {{ item.title }}
                              </h3>
                              <div class="know1" @click="toNewdetail(item.id)">
                                了解详情
                              </div>
                            </div>
                          </div>
                        </li>
                      </template>
                    </template>
                  </ul>
                </div>
                <template v-if="page < allpage">
                  <div class="lod1" @click="domore(em.id)">加载更多</div>
                </template>
              </div>
            </el-tab-pane>
          </template>
          <!--          <el-tab-pane label="企业新闻" name="firmnews">22</el-tab-pane>-->
        </el-tabs>
      </template>
    </div>

    <!-- 底部 -->
    <p-foot></p-foot>
  </div>
</template>
<script>
import {} from "../../http/api";
import { get } from "@/http/request";

export default {
  components: {},
  props: [],
  data() {
    return {
      newactiveName: "newall",
      banner: [],
      newlist: [],
      new_nav: [],
      new_one: [],
      total: "",
      page: 1,
      allpage: "",
      limit: 7,
    };
  },
  methods: {
    handleclikNews(tab, event) {
      this.page = 1;
      /**判断是否有值请求数据**/
      this.newlist = [];
      let smcate_id = tab.$attrs.newsid;
      console.log(smcate_id);
      get("/api/home/getall", {
        page: this.page,
        limit: this.limit,
        news_id: smcate_id,
      })
        .then((res) => {
          console.log(res);
          this.newlist = res.data.news.list;
          this.new_nav = res.data.news.new_nav;
          this.new_one = this.newlist[0];
          this.total = res.data.news.total;
          this.allpage = Math.ceil(this.total / this.limit);
          // console.log(this.newlist);
        })
        .catch((err) => {
          console.log(err);
        });
    },

    // 带参数
    toNewdetail(newid) {
      this.$router.push({ path: "/newdetail", query: { newid: newid } });
    },
    domore(val) {
      let smcate_id = val;
      //查看当前有几页
      let pa = Math.ceil(this.total / this.limit);
      if (this.page >= pa) {
        this.page = pa;
      } else {
        this.page++;
      }
      if (this.page <= pa) {
        get("/api/home/getall", {
          page: this.page,
          limit: this.limit,
          news_id: smcate_id,
        })
          .then((res) => {
            let newlist = res.data.news.list;
            this.new_one = newlist[0];
            this.new_nav = res.data.news.new_nav;
            newlist.forEach((item, index) => {
              this.newlist.push(item);
            });
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
     //通过导航获取数据
    getnewsNav(smcate_id){
      get("/api/home/getall", {
            page: this.page,
            limit: this.limit,
            news_id: smcate_id,
          })
            .then((res) => {
          this.newlist = res.data.news.list;
          this.new_one = this.newlist[0];
          this.new_nav = res.data.news.new_nav;
          this.total = res.data.news.total;
          this.allpage = Math.ceil(this.total / this.limit);
            })
            .catch((err) => {
              console.log(err);
            });
    }
  },
  mounted() {
      let news_id = this.$route.query.news_id;
      console.log(news_id)
      if(news_id){
        this.getnewsNav(news_id);return;
      }

    get("/api/home/getall", { page: 1, limit: 7 })
      .then((res) => {
        console.log(res.data);
        if (res.data.code == 200) {
          this.banner = res.data.banner;
          this.newlist = res.data.news.list;
          this.new_one = this.newlist[0];
          this.new_nav = res.data.news.new_nav;
          this.total = res.data.news.total;
          this.allpage = Math.ceil(this.total / this.limit);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  },
  computed: {},
  watch: {},
};
</script>
<style lang="less">
@import "../../less/index.less";
@import "../../assets/css/reset.css";

// .case_content {
//   margin-top: 50px;
//   margin-bottom: 60px;
// }
.case_content .el-tabs {
  margin-top: 50px;
  margin-bottom: 60px;
}
.case_content .el-tabs--card > .el-tabs__header {
  border: none;
}

.case_content .el-tabs--card > .el-tabs__header .el-tabs__nav {
  border: none;
}

/* //盈锋新闻 */
.new_content1 {
  width: 100%;
  margin-top: 20px;
}

.big_new1 {
  width: 100%;
  height: 484px;
  /* background-color: rgb(247, 247, 191); */
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.big_newpic1 {
  height: 100%;
  width: 52%;
}

.big_newpic1 img {
  height: 100%;
  width: 100%;
}

.big_newcontent1 {
  height: 100%;
  width: 48%;
  box-sizing: border-box;
  padding: 20px 30px;
  cursor: pointer;
}

.big_newcontent1 .new_time {
  margin-top: 40px;
  font-size: 14px;
  color: #333333;
}

.big_newcontent1 .new_detail {
  margin-top: 34px;
  color: #666666;
  font: 16px/24px "微软雅黑";
}

.big_newcontent1 h3 {
  margin-top: 16px;
  font: 24px/76px "微软雅黑";
}

.toNews1 {
  margin-top: 120px;
  width: 120px;
  height: 30px;
  background-color: #ffffff;
  text-align: center;
  line-height: 30px;
  color: #888888;
  border: 1px solid #e4e4e4;
}

.small_new1 {
  width: 100%;
  margin-top: 40px;
}

.small_new1 ul {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  // align-content: space-between;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
}

.small_new1 ul li {
  /* background-color: pink; */
  height: 23%;
  width: 45%;
  margin-bottom: 20px;
  box-sizing: border-box;
}
.small_new1 ul li:hover {
  margin-right: 5%;
  margin-left: 5%;
  transition: 0.5s;
  .know1 {
    background-color: #3a6cfe;
    color: #fff;
    cursor: pointer;
  }
}

.snew_content1 {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.snew_right1 {
  height: 100%;
  width: 45%;
  cursor: pointer;
}

.snew_right1 img {
  height: 100%;
  width: 100%;
}

.snew_left1 {
  width: 55%;
  padding-left: 18px;
}

.snew_left1 p {
  font: 14px;
  color: #333333;
  // margin-top: 20px;
  margin-bottom: 26px;
}

.snew_left1 h3 {
  font: 20px "微软雅黑";
  margin-bottom: 30px;
  overflow: hidden;
  height: 50px;
  width: 100%;
  cursor: pointer;
}

.snew_left1 .know1 {
  width: 92px;
  height: 30px;
  /* background-color: @primary; */
  font: 14px/30px "微软雅黑";
  color: #666666;
  text-align: center;
  border: 1px solid #e4e4e4;
}

.snew_left1 .know1:hover {
  background-color: #3a6cfe;
  color: #fff;
  cursor: pointer;
}

.toNews1:hover {
  background-color: #3a6cfe;
  color: #fff;
  cursor: pointer;
}

.lod1 {
  width: 200px;
  height: 50px;
  border: 1px solid #d4d4d4;
  font: 16px/50px "微软雅黑";
  line-height: 50px;
  color: #747474;
  text-align: center;
  margin: 0 auto;
  margin-top: 60px;
  cursor: pointer;
  margin-bottom: 60px;
}
.lod1:hover {
  color: #fff;
  cursor: pointer;
  background-color: #3a6cfe;
}
.new_detail1{
  height: 65px;
  overflow: hidden;
  margin-top: 10px;
}

/* 响应式布局 */

@media screen and (min-width: 992px) {
}

@media screen and (max-width: 992px) {
  .small_new1 ul li {
    width: 100%;
  }
  .big_new1 {
    height: 300px;
  }
  .toNews1 {
    margin-top: 50px;
  }
  .big_newcontent1 h3 {
    line-height: 50px;
  }
}

@media screen and (max-width: 768px) {
  .big_newcontent1 h3 {
    font-size: 20px;
    line-height: 30px;
    margin-top: 5px;
  }
}
@media screen and (max-width: 600px) {
  .small_new1 ul li {
    height: 140px;
  }.snew_left1 p{
    margin-bottom: 15px;
    margin-top: -10px;
  }
  .snew_left1 h3{
    margin-bottom: 25px;
  } 
}
@media screen and (max-width: 500px) {
  .tips {
    height: 300px;
  }
  .tips .tips_title h1 {
    font-size: 34px;
  }
  .tips .tips_title h2 {
    font-size: 32px;
  }
  .big_new1 {
    display: none;
  }
  .big_newcontent1 h3 {
    font-size: 20px;
    line-height: 30px;
    margin-top: 5px;
  }
  .toNews1 {
    margin-top: 20px;
  }
  .case_content .el-tabs__header{
    margin: 0;
  }
  .small_new1 ul li {
    height: 140px;
  }.snew_left1 p{
    margin-bottom: 15px;
    margin-top: -10px;
  }
  .snew_left1 h3{
    margin-bottom: 25px;
  } 
   .snew_left1 h3{
    height: 40px;
    font-size: 16px;
    line-height: 20px;
    overflow: hidden;
  }
   .snew_content1 {
    height: 80%;
  }
  .snew_right1 {
    width: 55%;
  }
  .small_new1 ul{
    height: 80%;
  }
  .snew_left1 .know1{
    display: none;
  }
}
</style>